package com.jdk.demo.io;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TimeServerHandle implements Runnable {

	private Socket socket;

	public TimeServerHandle(Socket socket){
		this.socket = socket;
	}

	public void run() {
		InputStream in = null;
		OutputStream out = null;
		try{
			in = socket.getInputStream();
			byte[] b = new byte[65535];
			in.read(b);
			System.out.println(new String(b));

			out = socket.getOutputStream();
			out.write("SERVER RECIEVED".getBytes());
			out.flush();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
				if(in != null){
					in.close();
				}
				if(out != null){
					out.close();
				}
				if(socket != null){
					socket.close();
				}
			}catch(IOException e){
				e.printStackTrace();
			}
		}
	}

}